<?php
session_start();
include_once "../apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();

$date = $_GET["date"];
$detail = $_GET["detail"];
$startTime = $_GET["start_time"];
$endTime = $_GET["end_time"];
$id = $_GET["id"];
$mode = $_GET["mode"];
if($mode == "" || $mode == null){
	$mode = $_POST["mode"];
}
if($mode =="getAllData"){
	$listData = $managerIUDS->queryData("doctor_time_table_id,detail,start_time,end_time,date", "doctor_time_table", "", "2", "");
	echo json_encode($listData);
}else if($mode =="insert"){
	$listData = $managerIUDS->queryData("end_time,start_time", "doctor_time_table", " WHERE date ='".$date."' AND (start_time ='".$startTime."' OR end_time='".$endTime."')", "1", "");
	if(sizeOf($listData) == 0){
		$arrData["date"] = "".$date."";
		$arrData["detail"] ="".$detail."";
		$arrData["start_time"] = "".$startTime."";
		$arrData["end_time"] ="".$endTime."";
		$arrData["create_date"] = "".date("Y-m-d")."";
		$arrData["create_by"] = "".$_SESSION["user_name"]."";
		$managerIUDS->inserData($arrData, "doctor_time_table");
		$arr = array('result' => 0);
		echo json_encode($arr);
	}else{
		$arr = array('result' => 1);
		echo json_encode($arr);
	}

}else if($mode =="update"){
	$listData = $managerIUDS->queryData("end_time,start_time", "doctor_time_table", " WHERE date ='".$date."' AND (start_time ='".$startTime."' OR end_time='".$endTime."')", "1", "");
	if(sizeOf($listData) == 0){
		$arrData["date"] = "".$date."";
		$arrData["detail"] ="".$detail."";
		$arrData["start_time"] = "".$startTime."";
		$arrData["end_time"] ="".$endTime."";
		$arrData["update_date"] = "".date("Y-m-d")."";
		$arrData["update_by"] = "".$_SESSION["user_name"]."";
		$arrPrimaryKey["doctor_time_table_id"] = "".$id."";
		$managerIUDS->updateData($arrData, "doctor_time_table", $arrPrimaryKey, "");
		$arr = array('result' => 0);
		echo json_encode($arr);
	}else{
		$arr = array('result' => 1);
		echo json_encode($arr);
	}

}else if($mode =="delete"){
	$arrPrimaryKey["doctor_time_table_id"] = "".$id."";
	$managerIUDS->deleteData("doctor_time_table", $arrPrimaryKey, "");
}else if($mode =="dropUpdate"){
	$arrData["date"] ="".$_GET["date"]."";
	$arrPrimaryKey["doctor_time_table_id"] = "".$id."";
	$managerIUDS->updateData($arrData, "doctor_time_table", $arrPrimaryKey, "");
}

?>